<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script type="text/javascript" src="./lib/vue.js"></script>
</head>
<body>
    <div id="box">
        <navbar myname="home" :myshow="false"></navbar>
        <navbar myname="list" :myshow="true"></navbar>
        <navbar myname="shopcar" :myshow="true"></navbar>
        <navbar :myname="parentname" :myshow="true"></navbar> 
        <navbar @myevent="handleEvent($event)"></navbar>
    </div>
    <script type="text/javascript">

        //子组件
        Vue.component("navbar",{
            template:`
                <div>
                    <button>返回</button>
                    navbar -- {{myname}}
                    <button v-show="myshow">首页</button>
                    <button @click="payMoney()">click</button>
                </div>
            `,
            //props:["myname","myshow"]  //接受父组件传来的属性
            props:{
                myname:String,
                myshow:Boolean
            },
            data(){
                return {
                    childname:"子组件的状态"
                }
            },
            methods:{
                payMoney(){
                    this.$emit("myevent",this.childname);
                }
            }
        })
        new Vue({
            el:"#box",
            data:{
                parentname:'父组件的状态'  
            },
            methods:{
                handleEvent(event){
                    console.log("接受子组件的值",event);
                }
            }
        })

    </script>
</body>
</html>